import {
  wxRequest
} from '../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({
  data: {
    imgUrl: app.globalData.imgUrl,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    list:[],
    pageNo:1,
    hasNextPage:false,
    tabstatus:1
  },


  
  onShow: function () {
    this.getlist()
  },



  //获取列表
  //获取列表
  getlist: function () {
    console.log(this.data.tabstatus, 'tabstatus')
    if (this.data.tabstatus == 1) {
      this.assessReq()
    } else {
      this.assessappendReq()
    }
  },


  // 评价
  assessReq: function () {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/odr/protected/order/listAssess?pageNo=' + this.data.pageNo,
      method: 'POST',
    }, (res) => {
      var list = res.list
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }

      this.setData({
        list: list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });
    })
  },

  // 追评评价
  assessappendReq: function () {
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/odr/protected/order/listAssess2?pageNo=' + this.data.pageNo,
      method: 'POST',
    }, (res) => {

      var list = res.list
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }

      this.setData({
        list: list,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });
      console.log(res, 'res')

    })
  },

  
  //tabl切换
  hadleTab: function (e) {
    var id = e.currentTarget.dataset.id
    this.setData({
      tabstatus: id,
      pageNo: 1
    })
    this.getlist()
  },


  //下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function () {
    this.setData({
      pageNo: 1
    })
    this.getlist();
  },

  //触底时，加载更多
  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },



  //查看详情 
  handleDetail: function (e) {
    wx.navigateTo({
      url: '/pages/good/detail/index?id=' + e.currentTarget.dataset.id
    })
  },


  //评价
  assess: function (e) {
    wx.navigateTo({
      url: '/pages/order/assess?id=' + e.currentTarget.dataset.id + '&itemid=' + e.currentTarget.dataset.itemid
    })
  },

  //追评
  assess2: function (e) {
    wx.navigateTo({
      url: '/pages/order/assess?id=' + e.currentTarget.dataset.id + '&itemid=' + e.currentTarget.dataset.itemid + '&assesstype=1'
    })
  },
})